package ce.com.cenewbluesdk.entity.k2;

import android.os.Parcel;
import android.os.Parcelable;

import ce.com.cenewbluesdk.CEBC;
import ce.com.cenewbluesdk.entity.BaseData;
import ce.com.cenewbluesdk.entity.CEDevData;

/**
 * Created by Administrator on 2015/7/2.
 * typedef struct
 * {
 * unsigned char clock_disp_type;			// config which type time disp style on dev
 * //0:12进制,1:24进制 , 0xFF:not set
 * unsigned char motor_call_enable;			//0:close ; 1:open ; 0xFF: not set
 * unsigned char motor_message_enable;     //0:close ; 1:open ; 0xFF: not set
 * unsigned char motor_alarm_enable;       //0:close ; 1:open ; 0xFF: not set
 * unsigned char motor_lowpower_enable;   //0:close ; 1:open ; 0xFF: not set
 * }dev_setting_struct;
 */
public class K2_SendDevSettingStruct extends BaseData implements Parcelable {

    public static final byte HEXADECIMAL_12 = 0;
    public static final byte HEXADECIMAL_24 = 1;

    public static final byte NOT_SET = (byte) 0xff;

    public static final byte SWTCH_CLOSE = 0;
    public static final byte SWTCH_OPEN = 1;


    public static final int watch_face_type=0;
    public static final int heart_enable_type=1;

    byte clock_disp_type;

    byte motor_message_enable;
    byte motor_alarm_enable;
    byte motor_lowpower_enable;
    byte watch_face;
    byte heart_enable;

    public K2_SendDevSettingStruct(byte clock_disp_type,
                                   byte motor_message_enable,
                                   byte motor_alarm_enable,
                                   byte motor_lowpower_enable) {
        this.clock_disp_type = clock_disp_type;

        this.motor_message_enable = motor_message_enable;
        this.motor_alarm_enable = motor_alarm_enable;
        this.motor_lowpower_enable = motor_lowpower_enable;

        this.watch_face= (byte) 0xff;
        this.heart_enable= (byte) 0xff;
    }


    public K2_SendDevSettingStruct(byte clock_disp_type,
                                   byte motor_message_enable,
                                   byte motor_alarm_enable,
                                   byte motor_lowpower_enable,
                                   byte watch_face,
                                   byte heart_enable) {
        this.clock_disp_type = clock_disp_type;

        this.motor_message_enable = motor_message_enable;
        this.motor_alarm_enable = motor_alarm_enable;
        this.motor_lowpower_enable = motor_lowpower_enable;

        this.watch_face= watch_face;
        this.heart_enable= heart_enable;
    }



    public K2_SendDevSettingStruct(byte  data , int type) {
        this.clock_disp_type = (byte) 0xff;

        this.motor_message_enable =  (byte) 0xff;
        this.motor_alarm_enable = (byte) 0xff;
        this.motor_lowpower_enable = (byte) 0xff;

        if(type == watch_face_type){
            this.watch_face= data;
            this.heart_enable=(byte) 0xff;
        }else if(type == heart_enable_type){
            this.watch_face= (byte) 0xff;
            this.heart_enable=data;
        }else{
            this.watch_face= (byte) 0xff;
            this.heart_enable=(byte) 0xff;
        }



    }

    public K2_SendDevSettingStruct(byte[] bytes) {
        this.clock_disp_type = bytes[0];
        this.motor_message_enable =  bytes[1];
        this.motor_alarm_enable =  bytes[2];
        this.motor_lowpower_enable =  bytes[3];
        this.watch_face =  bytes[4];
        this.heart_enable =  bytes[5];
    }

    protected K2_SendDevSettingStruct(Parcel in) {
        clock_disp_type = in.readByte();
        motor_message_enable = in.readByte();
        motor_alarm_enable = in.readByte();
        motor_lowpower_enable = in.readByte();
        watch_face = in.readByte();
        heart_enable = in.readByte();
    }

    public static final Creator<K2_SendDevSettingStruct> CREATOR = new Creator<K2_SendDevSettingStruct>() {
        @Override
        public K2_SendDevSettingStruct createFromParcel(Parcel in) {
            return new K2_SendDevSettingStruct(in);
        }

        @Override
        public K2_SendDevSettingStruct[] newArray(int size) {
            return new K2_SendDevSettingStruct[size];
        }
    };

    public byte[] getBytes() {
        byte[] bytes = new byte[6];
        bytes[0] = clock_disp_type;
        bytes[1]= motor_message_enable;  //motor_message_enable;

        bytes[2] = motor_alarm_enable;
        bytes[3] = motor_lowpower_enable;
        bytes[4] = watch_face; //watch_face;
        bytes[5] = heart_enable; //heart_enable;
        return bytes;
    }

    public byte getClock_disp_type() {
        return clock_disp_type;
    }

    public byte getMotor_alarm_enable() {
        return motor_alarm_enable;
    }

    public byte getMotor_lowpower_enable() {
        return motor_lowpower_enable;
    }

    public byte getMotor_message_enable() {
        return motor_message_enable;
    }

    public byte getWatch_face() {
        return watch_face;
    }

    public byte getHeart_enable() {
        return heart_enable;
    }

    public static int getItemSize() {
        return 6;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(clock_disp_type);
        dest.writeByte(motor_message_enable);
        dest.writeByte(motor_alarm_enable);
        dest.writeByte(motor_lowpower_enable);
        dest.writeByte(watch_face);
        dest.writeByte(heart_enable);
    }

    @Override
    public CEDevData toCEDevData() {
        CEDevData data=new CEDevData(CEBC.K2.CMD_TYPE_SEND,CEBC.K2.DATA_TYPE_SETTING);
        data.setData(getBytes());
        data.setItemL(getItemSize());
        data.setItemNumber(1);
        return data;
    }



}
